package com.fanrenqiji.modules.sys.entity;

import com.fanrenqiji.common.persistence.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import java.util.Date;

/**
 * @author lijian E-mail:ljz0721cx@163.com
 * @version 创建时间：2015年1月22日 上午9:51:08
 * @description 操作日志实体
 */
@Entity
@Table(name = "sys_log")
@DynamicInsert
@DynamicUpdate
public class Log extends BaseEntity {

	private static final long serialVersionUID = 1L;

	public static final String TYPE_ACCESS = "1"; //操作日志
	public static final String TYPE_EXCEPTION = "2";//错误异常日志
	
	/**
	 * 日志编号
	 */
	private Long id;
	/**
	 * 日志类型（1：接入日志；2：错误日志）
	 */
	private String type;
	/**
	 * 日志制造者
	 */
	private User createBy;
	/**
	 * 日志创建时间
	 */
	private Date createDate;
	/**
	 * 操作的用户Ip
	 */
	private String remoteAddr;
	/**
	 * 操作的URL
	 */
	private String requestUri;
	/**
	 * 操作方式
	 */
	private String method;
	/**
	 * 操作提交的数据
	 */
	private String params;
	/**
	 * 操作用户的代理信息,web端还是客户端
	 */
	private String userAgent;
	/**
	 * 异常信息
	 */
	private String exception;

	
	
	public Log() {
		super();
	}

	public Log(Long id) {
		this();
		this.id = id;
	}

	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="create_date")
	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	@Column(name="remote_addr")
	public String getRemoteAddr() {
		return remoteAddr;
	}

	public void setRemoteAddr(String remoteAddr) {
		this.remoteAddr = remoteAddr;
	}

	@Column(name = "request_url")
	public String getRequestUri() {
		return requestUri;
	}

	public void setRequestUri(String requestUri) {
		this.requestUri = requestUri;
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	public String getParams() {
		return params;
	}

	public void setParams(String params) {
		this.params = params;
	}

	@Column(name = "user_agent")
	public String getUserAgent() {
		return userAgent;
	}

	public void setUserAgent(String userAgent) {
		this.userAgent = userAgent;
	}

	public String getException() {
		return exception;
	}

	public void setException(String exception) {
		this.exception = exception;
	}

	
	@JsonIgnore
	@ManyToOne(fetch=FetchType.LAZY)
	@NotFound(action = NotFoundAction.IGNORE)
	@JoinColumn(name="user_id",updatable=false)
	public User getCreateBy() {
		return createBy;
	}

	public void setCreateBy(User createBy) {
		this.createBy = createBy;
	}

}
